package com.cmcc.waf.report.controller;


import com.cmcc.waf.report.feign.OpenAPIFeign;
import com.cmcc.waf.report.feign.model.EventVO;
import com.cmcc.waf.report.feign.model.ResponseVO;
import com.cmcc.waf.report.feign.model.WebSafeRequest;
import com.cmcc.waf.report.utils.DateUtils;
import com.cmcc.waf.report.utils.EcloudResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDate;
import java.util.List;

@RestController
public class AttackEventController {
    @Autowired
    private OpenAPIFeign feign;

    @PostMapping(value = "/event/top")
    public EcloudResult<List<EventVO>> getEventTop(@RequestBody @Validated WebSafeRequest request) {
        if (StringUtils.isEmpty(request.getStartTime()) || StringUtils.isEmpty(request.getEndTime())) {
            request.setStartTime(LocalDate.now().minusDays(30).atStartOfDay().format(DateUtils.DEFAULT_DATETIME_FMT));// 默认30天
            //request.setStartTime(LocalDate.now().atStartOfDay().format(DateUtils.DEFAULT_DATETIME_FMT)); // 默认当天
            request.setEndTime(LocalDate.now().atTime(23, 59, 59).format(DateUtils.DEFAULT_DATETIME_FMT));
        }
        ResponseVO<List<EventVO>> response = feign.realtimeEventTop(request);
        return new EcloudResult<List<EventVO>>().ok(response.getBody());
    }
}
